home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1996 / MacHack 1996.toast / Hacks / Hacks ’92 / PoliteNotification ƒ / PoliteNotification.π / NMInstallPatch.c next >
C/C++ Source or Header  |  1992-06-19  |  5KB  |  224 lines

  1. #ifndef THINK_C
  2.     #include <GestaltEQU.h>
  3.     #include <OSUtils.h>
  4.     #include <Notification.h>
  5.     #include <Resources.h>
  6. #endif
  7.  
  8.     #include <Traps.h>
  9.     #include <gestaltEQU.h>
  10.     #include <Processes.h>
  11.     #include "GestaltTalk.h"    
  12.     
  13. pascal void DeNotification();
  14. OSErr ShowInitIcon( short icon_num, short move_x_by);
  15. long  *GetStashSpotAddr();
  16. OSErr InstallGestaltTalk();
  17.  
  18. pascal OSErr GetIconSuite(Handle *iconSuite, short resID, short sel) =
  19. {0x303c, 0x0501, 0xabc9};
  20.  
  21. pascal OSErr NewIconSuite(Handle *iconSuite) = {0x303c, 0x0207, 0xabc9};
  22.  
  23. pascal OSErr AddIconToSuite(Handle *data, Handle suite, long restype) =
  24. {0x303c, 0x0609, 0xabc9};
  25.  
  26. Handle SetUpIcons()
  27. {
  28.     Handle    icon[6];
  29.     Handle    suite;
  30.     
  31.  
  32.     suite = GetResource('SICN',129);
  33.     DetachResource(suite);
  34.     return suite;
  35.  
  36.  
  37.  
  38.  
  39.  
  40. /*
  41.     Something bad is happening here and I don't want to find it.
  42.     If you fix this so it works, send me an AppleLink at BRIGHAM.
  43.     It was supposed to load in an icon family to be used for notifications that
  44.     do not use an icon.
  45. */
  46.  
  47. #if 0
  48.     icon[0] = Get1Resource('icl8',129);
  49.     DetachResource(icon);
  50.  
  51.     icon[1] = Get1Resource('icl4',129);
  52.     DetachResource(icon);
  53.  
  54.     icon[2] = Get1Resource('ics8',129);
  55.     DetachResource(icon);
  56.  
  57.     icon[3] = Get1Resource('ics4',129);
  58.     DetachResource(icon);
  59.  
  60.     icon[4] = Get1Resource('ICN#',129);
  61.     DetachResource(icon);
  62.  
  63.     icon[5] = Get1Resource('ics#',129);
  64.     DetachResource(icon);
  65.     
  66.     SetZone(SystemZone());
  67.     NewIconSuite(&suite);
  68.     SetZone(ApplicZone());
  69.     
  70.     AddIconToSuite(icon[0],suite,'icl8');
  71.     AddIconToSuite(icon[1],suite,'icl4');
  72.     AddIconToSuite(icon[2],suite,'ics8');
  73.     AddIconToSuite(icon[3],suite,'ics4');
  74.     AddIconToSuite(icon[4],suite,'ICN#');
  75.     AddIconToSuite(icon[5],suite,'ics#');
  76.  
  77.     return suite;
  78.     
  79. #endif
  80. }
  81.  
  82. pascal void main()
  83. {
  84.     Handle    initCodeHandle;
  85.     long    *localRealAddr;
  86.     short    err;
  87.     long    sysVersion;
  88.     
  89.     
  90.     /* don't load unless we are on 7.0 or later */
  91.     err = Gestalt(gestaltSystemVersion,&sysVersion);
  92.     if(sysVersion < 0x0700)    return;
  93.     
  94.     
  95.     if (err = InstallGestaltTalk()) {
  96.         DebugStr("\p InstallGestaltTalk Failed.");
  97.         return;
  98.     }
  99.     
  100.     initCodeHandle = GetResource('INIT',0);
  101.     DetachResource(initCodeHandle);
  102.  
  103.     localRealAddr = GetStashSpotAddr();
  104.     
  105.     *localRealAddr = GetOSTrapAddress( (short)0xA05E );
  106.     SetOSTrapAddress((long)DeNotification, (short)0xA05E);
  107.  
  108.     localRealAddr++;    
  109.     localRealAddr = SetUpIcons();
  110.  
  111.     (void) ShowInitIcon( 128, -1);
  112. }
  113.  
  114. OSErr InstallGestaltTalk()
  115. {
  116.     OSErr            err;
  117.     GestaltTalkPB    initPB;
  118.     
  119.     
  120.     err = NewGestalt(gestaltTalkSelector,(ProcPtr)GestaltTalkGestalt);
  121.     if(err)    {
  122.         DebugStr("\p InstallGestaltTalk - NewGestalt failed.");
  123.         goto bail;
  124.     }
  125.  
  126.     initPB.command = ginit;
  127.     initPB.datalength = 0;
  128.     initPB.data = nil;
  129.     initPB.gtData = nil;
  130.     
  131.     err =  GestaltTalk(&initPB);    
  132.     if(err)    {
  133.         DebugStr("\p InstallGestaltTalk - GestaltTalk ginit failed.");
  134.         goto bail;
  135.     }
  136.  
  137. bail:        
  138.     return err;
  139. }
  140.  
  141. short pstrlen(Str255 str)
  142. {
  143.     return str[0];
  144. }
  145.  
  146.  
  147. void KillNotificationDialog(NMRecPtr notification)
  148. {
  149.     long                *stashAddr;
  150.     GestaltTalkPB        writePB,getappPB;
  151.     short                err;
  152.     ProcessSerialNumber    curPSN;
  153.     ProcessInfoRec         info;
  154.     Str255                message;
  155.     short                divider = 0x01CA;
  156.     long                *iconSuite;
  157.     
  158.     if(notification->nmStr)
  159.     {
  160.         
  161.         if(!notification->nmIcon) {
  162.             /* add an icon to notification's that do not use one */
  163.             iconSuite = (Handle)GetStashSpotAddr();
  164.             iconSuite++;
  165.             notification->nmIcon = iconSuite;
  166.         }
  167.  
  168.         writePB.command = gwrite;
  169.         writePB.datalength = pstrlen(notification->nmStr) + 1;
  170.         writePB.data = notification->nmStr;
  171.         writePB.gtData = nil;
  172.         
  173.         err =  GestaltTalk(&writePB);
  174.  
  175.         /* Do the dirty deed... kill the notification dialog */
  176.         notification->nmStr = nil;        
  177.         
  178.         /* give the monitor that is registered some time */
  179.         getappPB.command = ggetapp;
  180.         getappPB.datalength = 0;
  181.         getappPB.data = nil;
  182.         getappPB.gtData = nil;
  183.         
  184.         err =  GestaltTalk(&getappPB);
  185.  
  186.         if( !err  ) {
  187.             err = WakeUpProcess(getappPB.data);
  188.         }
  189.     }
  190. }
  191.  
  192. pascal void DeNotification()
  193. {
  194.     
  195.     asm    {
  196.             move.l    d0,-(sp)                        // save some regs we use            
  197.             
  198.             move.l    a0,-(sp)                        // NMRecPtr on stack
  199.             jsr        KillNotificationDialog            // kill the dialog
  200.             addq.l    #4,sp                            // fix the stack
  201.             
  202. @callOriginal
  203.             jsr        GetStashSpotAddr                // get pointer to real NMinstall address
  204.  
  205.             movea.l    d0,a1                            // get pointer to storage
  206.             move.l    (a1),a1                            // save addr of NMInstall             
  207.             move.l    (sp)+,d0                        // restore regs used            
  208.             jmp     (a1)                            // 
  209.                                                     // 
  210.     }
  211. }
  212.  
  213. /* this gives us storage, but why didn't I use THINKs a4 crap? */
  214. long *GetStashSpotAddr()
  215. {
  216.     asm {
  217.             bsr.s @skipStorage
  218.             dc.l    0x00            // pointer to real NMINstall
  219.             dc.l    0x00            // 
  220.         @skipStorage:
  221.             move.l    (sp)+,d0
  222.     }
  223. }
  224.